from django.db import models

# Create your models here.
from apps.classapi.models import Class
from apps.user.models import User


class Tally(models.Model):
    """
    被记账的用户
    """
    user = models.ForeignKey(User, related_name="userses", verbose_name='记账用户', on_delete=models.CASCADE)
    aclass = models.ForeignKey(Class, related_name="aclas", verbose_name='被记账用户', on_delete=models.CASCADE)
    money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='金额')
    create_time = models.DateField(verbose_name='发布日期', null=True)
    update_time = models.DateField(auto_now=True, verbose_name="更新时间")
    text = models.CharField(verbose_name='备注', max_length=100)
    GENDER_CHOICES = (
        ('2', "欠款"),
        ('1', "还款"))
    kind = models.CharField(max_length=6, choices=GENDER_CHOICES, default="1", verbose_name="类型")

    class Meta:
        db_table = 'tb_tally'
        verbose_name = '欠款的用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.money


class Image(models.Model):
    user = models.ForeignKey(User, related_name="users", verbose_name='记账用户', on_delete=models.CASCADE)
    tally = models.ForeignKey(Tally, related_name="tallys", verbose_name='记账id', on_delete=models.CASCADE)
    imageUrl = models.CharField(max_length=255, verbose_name="头像")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_image'
        verbose_name = '欠款的用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.imageUrl
